package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
public class DishController {
    @Autowired
    private DishService dishService;

    @PostMapping
    @ApiModelProperty("新增菜品")
    public Result save(@RequestBody DishDTO dishDTO){
        log.info("新增的菜品：{}",dishDTO);
        dishService.save(dishDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiModelProperty("菜品分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult=dishService.pageQuery(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/{id}")
    @ApiModelProperty("根据id查询菜品")
    public Result<DishVO> lookDish(@PathVariable Long id){
        DishVO dishVO=dishService.lookDish(id);
        return Result.success(dishVO);
    }

    @PutMapping
    @ApiModelProperty("修改菜品")
    public Result updateDish(@RequestBody DishDTO dishDTO){

        dishService.updateDish(dishDTO);
        return Result.success();
    }
}
